import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:riki_push/enum/phone_platform.dart';

///
///  华为推送
///
class RikiBasePush {
  static const MethodChannel _channel = const MethodChannel('riki_push');

  /// 获取厂商类型
  static Future<PhonePlatform> get phonePlatform async {
    int platform = 0;
    if (Platform.isAndroid) {
      platform = await _channel.invokeMethod('getPhonePlatform');
    }
    return PhonePlatform.values[platform];
  }

  static Future<List<AndroidNotificationChannel>> getNotificationChannels(List<String> channelIds) async {
    if (Platform.isAndroid) {
      List<dynamic> channels = await _channel.invokeMethod('getNotificationChannels', channelIds);
      if (channels != null) {
        List<AndroidNotificationChannel> androidNotificationDetails = [];
        channels.forEach((element) {
          androidNotificationDetails.add(AndroidNotificationChannel(
            element['id'],
            '',
            '',
            playSound: element['playSound'],
            enableLights: element['enableLights'],
            enableVibration: element['enableVibration'],
            showBadge: element['showBadge'],
          ));
        });
        return androidNotificationDetails;
      }
    }
    return Future.value([]);
  }
}
